import { reactive, ref } from "vue";
import { useUser } from "@/stores/user";
import { formatTimestamp } from "@/comm/format";
const nameList = reactive({
    show: false,
    open: function () {
        // console.log("000")
        this.show = true;
    },
    close: function () {
        this.show = false;
    }
});

const tools = {
    fromtEnergy: function (num: number) {
        return num / 100;
    },
    fromtDate: function (time: number) {
        // const date = new Date(time);
        // return new Date(time).toLocaleDateString().concat('\t').concat(date.toLocaleTimeString());
        return formatTimestamp(time);
    },
    fromid: function (id: string | number) {
        const Id = String(id);
        // Id.length / 2
        return Id.slice(0, Id.length / 2).concat('***').concat(Id.slice(-3));
        // if (Id.length > 10) {
        // } else {
        //     return Id;
        // }
    }
}

const user = useUser();
const topList = ref<TopList[]>([]);
let currentUser = ref<TopList>({
    id: 0,
    top: 0,
    energy: 0,
    regTime: 0,
    luckEnergy: 0
});
async function getData() {
    const data = await user.getTopUser<NameList>();
    // console.log('yzt能量数据', data);
    if (data?.topList) {
        topList.value = data.topList;
    }
    if (data?.currentUser) {
        currentUser.value = data.currentUser;
        // currentUser.value.top = 3;
    }
}

export { nameList, user, tools, topList, currentUser, getData };

interface NameList {
    topList: TopList[];
    currentUser: TopList;
}

interface TopList {
    id: number;
    top: number;
    energy: number;
    regTime: number;
    luckEnergy: number;
}